Fix some issues with reference handling in the printing code. (#429902,
authorMatthias Clasen <mclasen@redhat.com>
Mon, 30 Apr 2007 04:45:33 +0000 (04:45 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 30 Apr 2007 04:45:33 +0000 (04:45 +0000)
2007-04-29  Matthias Clasen <mclasen@redhat.com>

        Fix some issues with reference handling in the printing
        code.  (#429902, Mathias Hasselmann)

        * gtk/gtkprintoperation.c (gtk_print_operation_finalize):
        Unref the print context, if we have one.
        (gtk_print_operation_done): Add a default ::done handler
        that unrefs the print context.
        (preview_ready): Take a reference on the print operation
        preview here.
        (print_pages_idle): ...not here,
        (preview_print_idle_done): ...and release it here.

        * tests/print-editor.c (preview_cb): Take a reference
        on the print operation here.

svn path=/trunk/; revision=17722

ChangeLog
gtk/gtkprintoperation.c
tests/print-editor.c

index 7178af325c921a0370c805c6b6c9c2b1f6c14665..a20d462462b43971b613b19033784fc95f3d3614 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-04-29  Matthias Clasen <mclasen@redhat.com>
+
+       Fix some issues with reference handling in the printing
+       code.  (#429902, Mathias Hasselmann)
+
+       * gtk/gtkprintoperation.c (gtk_print_operation_finalize):
+       Unref the print context, if we have one.
+       (gtk_print_operation_done): Add a default ::done handler 
+       that unrefs the print context.
+       (preview_ready): Take a reference on the print operation
+       preview here.
+       (print_pages_idle): ...not here,
+       (preview_print_idle_done): ...and release it here.
+
+       * tests/print-editor.c (preview_cb): Take a reference
+       on the print operation here.
+
 2007-04-29  Matthias Clasen <mclasen@redhat.com>
 
        * gtk/gtkprintoperation.c (print_pages_idle): Don't get
index ed038152c77b12f78094efdb9238ca7f64ed9d2e..fe92a5cf6dbe678386e7e4d8f2a205f133787ba5 100644 (file)
@@ -120,6 +120,9 @@ gtk_print_operation_finalize (GObject *object)
   if (priv->print_settings)
     g_object_unref (priv->print_settings);
   
+  if (priv->print_context)
+    g_object_unref (priv->print_context);
+
   g_free (priv->export_filename);
   g_free (priv->job_name);
   g_free (priv->custom_tab_label);
@@ -396,6 +399,8 @@ preview_print_idle_done (gpointer data)
   g_free (pop->filename);
 
   gtk_print_operation_preview_end_preview (pop->preview);
+
+  g_object_unref (op);
   g_free (pop);
 }
 
@@ -447,6 +452,8 @@ preview_ready (GtkPrintOperationPreview *preview,
   pop->page_nr = 0;
   pop->print_context = context;
 
+  g_object_ref (preview);
+      
   gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE + 10,
                             preview_print_idle,
                             pop,
@@ -495,6 +502,18 @@ gtk_print_operation_create_custom_widget (GtkPrintOperation *operation)
   return NULL;
 }
 
+static void
+gtk_print_operation_done (GtkPrintOperation *operation)
+{
+  GtkPrintOperationPrivate *priv = operation->priv;
+
+  if (priv->print_context)
+    {
+      g_object_unref (priv->print_context);
+      priv->print_context = NULL;
+    } 
+}
+
 static gboolean
 custom_widget_accumulator (GSignalInvocationHint *ihint,
                           GValue                *return_accu,
@@ -523,6 +542,7 @@ gtk_print_operation_class_init (GtkPrintOperationClass *class)
  
   class->preview = gtk_print_operation_preview_handler; 
   class->create_custom_widget = gtk_print_operation_create_custom_widget;
+  class->done = gtk_print_operation_done;
   
   g_type_class_add_private (gobject_class, sizeof (GtkPrintOperationPrivate));
 
@@ -1935,7 +1955,6 @@ print_pages_idle_done (gpointer user_data)
                   GTK_PRINT_OPERATION_RESULT_APPLY);
   
   g_object_unref (data->op);
-
   g_free (data);
 }
 
@@ -2129,8 +2148,6 @@ print_pages_idle (gpointer user_data)
     {
       done = TRUE;
 
-      g_object_ref (data->op);
-      
       g_signal_emit_by_name (data->op, "ready", priv->print_context);
       goto out;
     }
index 8e11e4bbb7a5805013d907783b7f7d509c9870e1..9b47ce8d55e3d99e53294959f99d33376167b397 100644 (file)
@@ -578,7 +578,7 @@ preview_cb (GtkPrintOperation        *op,
   gtk_print_context_set_cairo_context (context, cr, 72, 72);
   cairo_destroy (cr);
   
-  pop->op = op;
+  pop->op = g_object_ref (op);
   pop->preview = preview;
   pop->spin = page;
   pop->area = da;